package com.epfresh.supplier.activity;
import com.epfresh.api.entity.RequestTag;
import com.epfresh.api.widget.*;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.epfresh.api.entity.RequestEntitySupply;
import com.epfresh.api.entity.ResponseEntity;
import com.epfresh.api.global.BaseActivity;
import com.epfresh.api.http.HttpRequest;
import com.epfresh.api.http.OnRequestListener;
import com.epfresh.api.universalimageloader.core.ImageLoader;
import com.epfresh.api.utils.T;
import com.epfresh.supplier.R;
import com.epfresh.supplier.adapter.OrderStateViewBinder;
import com.epfresh.supplier.constant.Constant;
import com.epfresh.supplier.dialog.AgentSwitchDialog;
import com.epfresh.supplier.entity.*;
import com.epfresh.supplier.wxapi.WXPayEntryActivity;
import com.google.gson.Gson;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Timer;
import java.util.TimerTask;

import multitype.MultiTypeAdapter;

public class OrderDetailGroupActivity extends BaseActivity {


    TextView tv_order_detail_group_id, tv_order_detail_group_code;
    TextView tv_order_detail_group_state,tv_order_detail_group_goods_logistics,tv_order_detail_group_money_detail,tv_order_detail_group_date,tv_order_detail_group_top_button;
    RecyclerView rv_order_detail_group_state;
    View ll_order_detail_group_address;
    TextView tv_order_detail_group_address,tv_order_detail_group_base_title;
    View iv_order_detail_group_phone,tv_order_detail_group_store_go,rl_product;

    ImageView iv_order_detail_group_product;
    TextView tv_order_detail_group_product_title, tv_order_detail_group_product_price, tv_order_detail_group_product_package,tv_order_detail_group_product_size_detail;

    TextView tv_order_detail_group_money_percent,tv_order_detail_group_money_all;

    CommonInputItemThin ciMoneyShall,ciMoneyGoods, ciMoneyPost, ciMoneyMinus, ciMoneyFact,  ciMoneyAli, ciMoneyWe, ciMoneyReturn, ciMoneyNo;


    TextView tv_order_detail_group_minus, tv_order_detail_group_sure,tv_order_detail_group_cancel, tv_order_detail_group_pay_remind,tv_order_detail_group_pay_pre;
    View rl_operate;

    String id;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        initView();
        id = getIntent().getStringExtra("id");
        if(id!=null){
            requestOrderInfo();
        }else {
            T.toast("没收到订单号");
            finish();
        }
    }


    void setNotNull(CommonInputItemThin itemV, String itemS) {
        if (itemS == null || "".equals(itemS) || "0".equals(itemS) || "0.00".equals(itemS) || "null".equals(itemS) || "0.0".equals(itemS) || "-0.00".equals(itemS)) {
            itemV.setVisibility(View.GONE);
        } else {
            itemV.setContentText(itemS + "元");
            itemV.setVisibility(View.VISIBLE);
        }
    }


    OrderStateViewBinder binder;
    MultiTypeAdapter mStateAdapter = new MultiTypeAdapter();
    List<Object> mStateItems = new ArrayList<>();

    void initView(){
        tvBack.setVisibility(View.VISIBLE);
        setContentView(R.layout.activity_order_detail_on_group);
        rl_product = findViewById(R.id.rl_product);
        rl_product.setOnClickListener(this);


        tv_order_detail_group_code = (TextView) findViewById(R.id.tv_order_detail_group_code);
        tv_order_detail_group_id = (TextView)findViewById(R.id.tv_order_detail_group_id);
        tv_order_detail_group_state = (TextView)findViewById(R.id.tv_order_detail_group_state);
        tv_order_detail_group_goods_logistics = (TextView)findViewById(R.id.tv_order_detail_group_goods_logistics);
        tv_order_detail_group_goods_logistics.setOnClickListener(this);
        tv_order_detail_group_money_detail = (TextView)findViewById(R.id.tv_order_detail_group_money_detail);
        tv_order_detail_group_date = (TextView)findViewById(R.id.tv_order_detail_group_date);
        tv_order_detail_group_top_button = (TextView)findViewById(R.id.tv_order_detail_group_top_button);
        tv_order_detail_group_top_button.setOnClickListener(this);

        ll_order_detail_group_address = findViewById(R.id.ll_order_detail_group_address);
        tv_order_detail_group_address = (TextView)findViewById(R.id.tv_order_detail_group_address);
        tv_order_detail_group_base_title = (TextView)findViewById(R.id.tv_order_detail_group_base_title);
        tv_order_detail_group_store_go = findViewById(R.id.tv_order_detail_group_store_go);
        tv_order_detail_group_store_go.setOnClickListener(this);
        iv_order_detail_group_phone = findViewById(R.id.iv_order_detail_group_phone);
        iv_order_detail_group_phone.setOnClickListener(this);

        rv_order_detail_group_state = (RecyclerView)findViewById(R.id.rv_order_detail_group_state);
        LinearLayoutManager layoutManager = new LinearLayoutManager(this);
        layoutManager.setOrientation(LinearLayoutManager.HORIZONTAL);
        rv_order_detail_group_state.setLayoutManager(layoutManager);
        binder = new OrderStateViewBinder();
        mStateAdapter.register(OrderDetailAgent.ContentBean.StageStatusListBean.class, binder);
        rv_order_detail_group_state.setAdapter(mStateAdapter);
        mStateAdapter.setItems(mStateItems);

        tv_order_detail_group_product_title = (TextView)findViewById(R.id.tv_order_detail_group_product_title);
        tv_order_detail_group_product_price = (TextView)findViewById(R.id.tv_order_detail_group_product_price);
        tv_order_detail_group_product_size_detail = (TextView)findViewById(R.id.tv_order_detail_group_product_size_detail);
        tv_order_detail_group_product_package = (TextView)findViewById(R.id.tv_order_detail_group_product_package);
        iv_order_detail_group_product = (ImageView)findViewById(R.id.iv_order_detail_group_product);



        tv_order_detail_group_money_percent = (TextView)findViewById(R.id.tv_order_detail_group_money_percent);
        tv_order_detail_group_money_all = (TextView)findViewById(R.id.tv_order_detail_group_money_all);

        rl_operate = findViewById(R.id.rl_operate);
        tv_order_detail_group_minus = (TextView)findViewById(R.id.tv_order_detail_group_minus);
        tv_order_detail_group_sure = (TextView)findViewById(R.id.tv_order_detail_group_sure);
        tv_order_detail_group_cancel = (TextView)findViewById(R.id.tv_order_detail_group_cancel);
        tv_order_detail_group_pay_remind = (TextView)findViewById(R.id.tv_order_detail_group_pay_remind);
        tv_order_detail_group_pay_pre = (TextView)findViewById(R.id.tv_order_detail_group_pay_pre);

        tv_order_detail_group_minus.setOnClickListener(this);
        tv_order_detail_group_sure.setOnClickListener(this);
        tv_order_detail_group_cancel.setOnClickListener(this);
        tv_order_detail_group_pay_remind.setOnClickListener(this);
        tv_order_detail_group_pay_pre.setOnClickListener(this);


        ciMoneyShall = (CommonInputItemThin) findViewById(R.id.ci_money_should);
        ciMoneyGoods = (CommonInputItemThin)findViewById(R.id.ci_money_goods);
        ciMoneyPost = (CommonInputItemThin)findViewById(R.id.ci_money_post);
        ciMoneyMinus = (CommonInputItemThin)findViewById(R.id.ci_money_minus);
        ciMoneyFact = (CommonInputItemThin)findViewById(R.id.ci_money_fact);
        ciMoneyAli = (CommonInputItemThin)findViewById(R.id.ci_money_ali);
        ciMoneyWe = (CommonInputItemThin)findViewById(R.id.ci_money_we);
        ciMoneyReturn = (CommonInputItemThin)findViewById(R.id.ci_money_return);
        ciMoneyNo = (CommonInputItemThin)findViewById(R.id.ci_money_no);

        rightbtn.setVisibility(View.GONE);
        toolbarTitle.setText("订单详情");
    }

    public void onClick(View view) {
        Intent intent;
        switch (view.getId()) {
            case R.id.rl_product:
                intent = new Intent(this, BaseProductDetailActivity.class);
                intent.putExtra("baseStoreId", data.getBaseStoreId());
                intent.putExtra("productId", data.getProductId());
                startActivity(intent);
                break;
            case R.id.iv_order_detail_group_phone:
                Intent intent_call0 = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:" + data.getBaseManagerPhone()));//调出来拨打页面；
                startActivity(intent_call0);
                break;
            case R.id.tv_order_detail_group_store_go:
                intent = new Intent(this, BaseStoreInfoActivity.class);
                intent.putExtra("baseStoreId", data.getBaseStoreId());
                startActivity(intent);
                break;
            case R.id.tv_order_detail_group_top_button:
                addProduct();
/*                if("".equals(view.getTag())){
                    intent = new Intent(this, ProductActivity.class);
                    intent.putExtra("productType", 2);
                    startActivity(intent);
                }else {
                    intent = new Intent(this, ProductActivity.class);
                    intent.putExtra("productType", 1);
                    startActivity(intent);
                }*/
                break;
            case R.id.baseback:
                // 返回上一页
                finish();
                break;
            case R.id.rightbtn:
                intent = new Intent(this, WebActivity.class);
                intent.putExtra(Constant.KEY_WEB_URL, Constant.URL_HELP_REDUCTION);
                intent.putExtra(Constant.KEY_WEB_TITLE, getString(R.string.help));
                startActivity(intent);
                break;
            case R.id.tv_order_detail_group_goods_logistics:
                Intent logisticsInfo = new Intent(this, OrderLogisticsGroupInfoActivity.class);
                logisticsInfo.putExtra("orderId", data.getOrderId());
                startActivity(logisticsInfo);
                break;

            case R.id.tv_order_detail_group_minus:
                intent = new Intent(this, ReturnApplicationInfoActivity.class);
                intent.putExtra("orderId", data.getOrderId());
                startActivityForResult(intent, 0x002);//2，减免退；3，支付；
                break;
            case R.id.tv_order_detail_group_sure:
                //requestSure(data.getOrderId());
                openDialog();

                break;
            case R.id.tv_order_detail_group_cancel:
                requestCancel(data.getOrderId());
                break;
            case R.id.tv_order_detail_group_pay_pre:
                intent = new Intent(this, WXPayEntryActivity.class);
                //intent.putExtra("requiredProductPayFirst", requiredProductPayFirst);//是否第一笔
                intent.putExtra("payFirstCountDown", ""+mPayCountDown);//倒计时
                intent.putExtra("orderId", data.getOrderId());
                //1订金 2尾款+运费
                intent.putExtra("receiptType", "1");
                startActivityForResult(intent, 0x003);//2，减免退；3，支付首款；4，支付尾款

                break;
            case R.id.tv_order_detail_group_pay_remind:
                intent = new Intent(this, WXPayEntryActivity.class);
                //intent.putExtra("requiredProductPayFirst", requiredProductPayFirst);//是否第一笔
                intent.putExtra("payFirstCountDown", ""+mPayCountDown);//倒计时
                intent.putExtra("orderId", data.getOrderId());
                //1订金 2尾款+运费
                intent.putExtra("receiptType", "2");
                startActivityForResult(intent, 0x004);//2，减免退；3，支付首款；4，支付尾款
                break;


        }
    }


    private AgentSwitchDialog sureDialog;

    private void openDialog() {
        if(!"10".equals(data.getJmtStatus())){
            requestSure(data.getOrderId());
        }else {
            sureDialog = new AgentSwitchDialog(this, true);

            sureDialog.setTitle("");//是否暂停代办？
            sureDialog.setMessage("有退款在申请中，确认交易则将取消退款，是否确认交易？");//如暂停代办，将无法获得此基地的代办订单

            sureDialog.setOnPositiveClickListener("确定交易", new AgentSwitchDialog.onPositiveClickListener() {
                @Override
                public void onPositiveClickListener() {
                    sureDialog.dismiss();
                    requestSure(data.getOrderId());
                }

            });
            sureDialog.setOnNegativeClickListener("取消", new AgentSwitchDialog.onNegativeClickListener() {
                @Override
                public void onNegativeClickListener() {
                    sureDialog.dismiss();
                }
            });
            sureDialog.show();
        }
    }

    private void addProduct() {
        if(data==null||data.getOrderId()==null||data.getProductId()==null){
            T.toast("数据有误，请稍后重试");
            return;
        }
        Intent intent = new Intent(this, ProductAddActivity.class);
        intent.putExtra("isFrom","fromBaseResell");
        intent.putExtra("is_first", false);
        intent.putExtra("productId", data.getProductId());

        intent.putExtra("orderId",data.getOrderId());
        intent.putExtra("listType", 3);//
        intent.putExtra(Constant.TYPE, "1");
        startActivity(intent);
    }


    @Override
    protected void onActivityResult(int requestcode, int resultcode, Intent date) {
        super.onActivityResult(requestcode, resultcode, date);
        if (/*requestcode == 0x001 && */resultcode == RESULT_OK) {
            requestOrderInfo();
        }
    }
    @Override
    protected void onDestroy() {
        timerStop();
        super.onDestroy();
    }

    OnRequestListener<OrderDetailGroup> onRequestListener = new OnRequestListener<OrderDetailGroup>() {
        @Override
        public OrderDetailGroup jsonToObj(String responseStr) {
            return new Gson().fromJson(responseStr, OrderDetailGroup.class);
        }

        @Override
        public void onFail(int failCode, Object arg, Object tag) {
            hideProgressDialog();
            showExceptionView(R.mipmap.upload_error, "服务器出现小错误，请稍后再试", HttpRequest.FAIL_NET_FAULT);
        }

        @Override
        public void onResponseError(int failCode, Object arg, Object tag) {
            hideProgressDialog();
            showExceptionView(R.mipmap.upload_error, arg + "", HttpRequest.FAIL_NET_FAULT);
        }
        @Override
        public void onStart(Object tag) {
            showProgressDialog();
        }

        @Override
        public void onResponse(ResponseEntity<OrderDetailGroup> response, Object tag) {
            hideProgressDialog();
            OrderDetailGroup responseElement = response.getResponseElement();
            updateOrderInfo(responseElement);
        }
    };
    String cmdOrderDetails = "pm-order/baseorder/order/detail";

    public void requestOrderInfo() {
        RequestEntitySupply<Map<String, String>> entity = new RequestEntitySupply<>();
        entity.setCmd(cmdOrderDetails);
        Map<String, String> map = new HashMap<>();
        map.put("orderId",id);
        entity.setParameters(map);
        request(entity, cmdOrderDetails, onRequestListener);
    }
    OrderDetailGroup data;

    public void updateOrderInfo(OrderDetailGroup data) {
        this.data = data;
        tv_order_detail_group_id.setText("单号："+data.getOrderNo());
        if(data.getInspectCode()==null||"".equals(data.getInspectCode())){
            tv_order_detail_group_code.setVisibility(View.GONE);
        }else {
            tv_order_detail_group_code.setVisibility(View.VISIBLE);
            tv_order_detail_group_code.setText("交货码："+data.getInspectCode());
        }
        tv_order_detail_group_state.setText(data.getStatusAndDate());
        tv_order_detail_group_money_detail.setText(data.getPriceTitle() + data.getPriceAndYuan());
        if(data.getPriceTitle()==null) {
            tv_order_detail_group_money_detail.setVisibility(View.INVISIBLE);
        }else {
            tv_order_detail_group_money_detail.setVisibility(View.VISIBLE);
        }
        tv_order_detail_group_date.setText(data.getCreateTime());//"下单时间："+data.getCreateTime());
        if(data.getTopButtonList()==null||data.getTopButtonList().size()==0){
            tv_order_detail_group_top_button.setVisibility(View.GONE);
        }else {
            tv_order_detail_group_top_button.setVisibility(View.VISIBLE);
            tv_order_detail_group_top_button.setText(data.getTopButtonList().get(0).getTitle());
            tv_order_detail_group_top_button.setTag(data.getTopButtonList().get(0).getCode());
        }
/*        if(data.getOrderProgressList().size()==2){
            data.getOrderProgressList().add(1,new OrderDetailAgent.ContentBean.StageStatusListBean());
            data.getOrderProgressList().add(1,new OrderDetailAgent.ContentBean.StageStatusListBean());
            data.getOrderProgressList().add(1,new OrderDetailAgent.ContentBean.StageStatusListBean());
        }*/

        if(data.getAgencyReceiveAddress()==null||"".equals(data.getAgencyReceiveAddress())){
            ll_order_detail_group_address.setVisibility(View.GONE);
        }else {
            tv_order_detail_group_address.setText(data.getAgencyReceiveAddress());
        }
        mStateItems.addAll(data.getOrderProgressList());
        mStateAdapter.notifyDataSetChanged();
        if(data.getOrderProgressList()!=null&&data.getOrderProgressList().size()>5) {
            int position=0;
            for(int i=0;i<data.getOrderProgressList().size();i++){
                if(data.getOrderProgressList().get(i).isCurNode()){
                    position = i;
                    break;
                }
            }
            if(position>4)
                rv_order_detail_group_state.scrollToPosition(position-2);
        }
        tv_order_detail_group_base_title.setText(data.getBaseStoreName());
        ImageLoader.getInstance().displayImage(data.getProductImg(), iv_order_detail_group_product);

        tv_order_detail_group_product_title.setText(data.getProductTitle());
        tv_order_detail_group_product_price.setText(data.getProductPriceUnit()+"元/"+data.getChargeUnit());
        tv_order_detail_group_product_package.setText(data.getPack());
        tv_order_detail_group_product_size_detail.setText("购买数量："+data.getProductCount()+data.getChargeUnit());

        initMoney(data);
        initBottomButton(data);
    }


    void initMoney(OrderDetailGroup detail){
        ciMoneyShall.setContentText("" + detail.getCope() + "元");
        ciMoneyGoods.setContentText("" + detail.getProductPrice() + "元");
        if (detail.getRequiredFreight() == null || "".equals(detail.getRequiredFreight())  || "null".equals(detail.getRequiredFreight()) )
            detail.setRequiredFreight("0");
        ciMoneyPost.setContentText("" + detail.getRequiredFreight() + "元");
        //setNotNull(ciMoneyPost, detail.getRequiredFreight());
        setNotNull(ciMoneyMinus, detail.getSumJmtPrice());
        ciMoneyFact.setContentText("" + detail.getPaid() + "元");
        setNotNull(ciMoneyAli, detail.getAlipayPaid());
        setNotNull(ciMoneyWe, detail.getWeChatPaid());
        setNotNull(ciMoneyReturn, detail.getSumRefund());
        ciMoneyNo.setContentText(""+detail.getUnPayTotal()+"元");
        //setNotNull(ciMoneyNo, detail.getUnPayTotal()); 未付要求始终显示
    }

    void initBottomButton(OrderDetailGroup data){
        rl_operate.setVisibility(View.GONE);
        tv_order_detail_group_pay_remind.setVisibility(View.GONE);
        tv_order_detail_group_pay_pre.setVisibility(View.GONE);
        tv_order_detail_group_sure.setVisibility(View.GONE);
        tv_order_detail_group_cancel.setVisibility(View.GONE);
        tv_order_detail_group_minus.setVisibility(View.GONE);

        for (OrderDetailGroup.BottomButtonListBean bean:data.getBottomButtonList()) {
            switch (bean.getCode()){
                case "supplyPayFirst":
                    tv_order_detail_group_pay_pre.setVisibility(View.VISIBLE);
                    rl_operate.setVisibility(View.VISIBLE);
                    mPayCountDown = bean.getRemainTime();
                    payInfo = bean.getTitle()+"\n";
                    timerStart(tv_order_detail_group_pay_pre);
                    break;
                case "supplyCancelOrder":
                    tv_order_detail_group_cancel.setText(bean.getTitle());
                    tv_order_detail_group_cancel.setVisibility(View.VISIBLE);
                    rl_operate.setVisibility(View.VISIBLE);
                    break;
                case "supplyPayLast":
                    tv_order_detail_group_pay_remind.setVisibility(View.VISIBLE);
                    rl_operate.setVisibility(View.VISIBLE);
                    mPayCountDown = bean.getRemainTime();
                    payInfo = bean.getTitle()+"\n";
                    timerStart(tv_order_detail_group_pay_remind);
                    break;
                case "supplyApplyFefund":
                    tv_order_detail_group_minus.setText(bean.getTitle());
                    tv_order_detail_group_minus.setVisibility(View.VISIBLE);
                    rl_operate.setVisibility(View.VISIBLE);
                    break;
                case "supplyCheckGoods":
                    tv_order_detail_group_sure.setText(bean.getTitle());
                    tv_order_detail_group_sure.setVisibility(View.VISIBLE);
                    rl_operate.setVisibility(View.VISIBLE);
                    break;
            }
        }
    }

    long mPayCountDown;


    Timer timer;
    boolean isTimerAlive;
    TimerTask task ;

    String payInfo;


    public void timerStart(final TextView mTvMoneyTime) {
        timerStop();
        timer = new Timer();

        task =  new TimerTask() {
            @Override
            public void run() {
                runOnUiThread(new TimerTask() {
                    @Override
                    public void run() {
                        try {
                            if (isTimerAlive){
                                mPayCountDown --;
                                String timeFlag = "";
                                if (mPayCountDown > 60) {
                                    long hour = mPayCountDown/3600;
                                    long minus = mPayCountDown / 60;
                                    long sec = mPayCountDown % 60;
                                    if (hour < 10) {
                                        timeFlag = "0" + hour;


                                        if (minus < 10) {
                                            timeFlag += ":0" + minus;
                                        } else {
                                            timeFlag += ":" + minus;
                                        }
                                        if (sec < 10) {
                                            timeFlag += ":0" + sec;
                                        } else {
                                            timeFlag += ":" + sec;
                                        }

                                    } else {
                                        timeFlag = "" + hour;

                                        if (minus < 10) {
                                            timeFlag += ":0" + minus;
                                        } else {
                                            timeFlag += ":" + minus;
                                        }
                                        if (sec < 10) {
                                            timeFlag += ":0" + sec;
                                        } else {
                                            timeFlag += ":" + sec;
                                        }

                                    }

                                } else if (mPayCountDown > 0) {
                                    if (mPayCountDown < 10) {
                                        timeFlag = "00:00:0" + mPayCountDown;
                                    } else {
                                        timeFlag = "00:00:" + mPayCountDown;
                                    }
                                } else {
                                    timerStop();
                                    //mTvMoneyTime.setText(payInfo + "00:00:00");
                                    if(mTvMoneyTime.getId() == R.id.tv_order_detail_group_pay_pre) {
                                        mTvMoneyTime.setVisibility(View.GONE);
                                    }else{
                                        mTvMoneyTime.setText("支付尾款");
                                    }
                                    //requestOrderInfo();
                                    return;
                                }
                                mTvMoneyTime.setText(payInfo + timeFlag);
                            }


                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                    }
                });

            }
        };
        isTimerAlive = true;

        timer.schedule(task, 0, 1000);
    }

    public void timerStop() {
        isTimerAlive = false;
        if (timer != null) {
            timer.cancel();
            timer = null;
        }
        if (task != null){
            task.cancel();
            task = null;
        }
    }







    void requestSure(String id){
        RequestEntitySupply<Map<String, String>> entity = new RequestEntitySupply<>();
        Map<String, String> map = new HashMap<>();
        map.put("orderId", id);
        entity.setCmd("pm-order/baseorder/order/checkgoods");
        entity.setParameters(map);
        RequestTag requestTag = new RequestTag();
        requestTag.tag = "pm-order/baseorder/order/checkgoods";
        request(entity, requestTag, onRequestSurelListener);
    }

    OnRequestListener<StatusEntity> onRequestSurelListener = new OnRequestListener<StatusEntity>() {
        @Override
        public StatusEntity jsonToObj(String responseStr) {
            return new Gson().fromJson(responseStr, StatusEntity.class);
        }

        @Override
        public void onFail(int failCode, Object arg, Object tag) {
            T.toast("请求失败，请重试");
            hideProgressDialog();
        }

        @Override
        public void onResponseError(int failCode, Object arg, Object tag) {
            T.toast("请求失败，请重试");
            hideProgressDialog();

        }

        @Override
        public void onStart(Object tag) {
            //showProgressView();
            showProgressDialog();
        }

        @Override
        public void onResponse(ResponseEntity<StatusEntity> response, Object tag) {
            //页面第一次调用网络请求接口并成功
            hideProgressDialog();
            StatusEntity orderResponse = response.getResponseElement();
            if(orderResponse.isSuccess()){
                requestOrderInfo();
            }else{
                T.toast("取消失败，请联系客服");
            }
        }
    };


    void requestCancel(String id){
        RequestEntitySupply<Map<String, String>> entity = new RequestEntitySupply<>();
        Map<String, String> map = new HashMap<>();
        map.put("orderId", id);
        entity.setCmd("pm-order/baseorder/order/cancel");
        entity.setParameters(map);
        RequestTag requestTag = new RequestTag();
        requestTag.tag = "pm-order/baseorder/order/cancel";
        request(entity, requestTag, onRequestCancelListener);
    }

    OnRequestListener<StatusEntity> onRequestCancelListener = new OnRequestListener<StatusEntity>() {
        @Override
        public StatusEntity jsonToObj(String responseStr) {
            return new Gson().fromJson(responseStr, StatusEntity.class);
        }

        @Override
        public void onFail(int failCode, Object arg, Object tag) {
            T.toast("请求失败，请重试");
            hideProgressDialog();
        }

        @Override
        public void onResponseError(int failCode, Object arg, Object tag) {
            T.toast("请求失败，请重试");
            hideProgressDialog();

        }

        @Override
        public void onStart(Object tag) {
            //showProgressView();
            showProgressDialog();
        }

        @Override
        public void onResponse(ResponseEntity<StatusEntity> response, Object tag) {
            //页面第一次调用网络请求接口并成功
            hideProgressDialog();
            StatusEntity orderResponse = response.getResponseElement();
            if(orderResponse.isSuccess()){
                requestOrderInfo();
            }else{
                T.toast("取消失败，请联系客服");
            }
        }
    };
}
